package com.edison.democommon.api;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Getter;
import lombok.Setter;


/**
 * @author edison
 */
@Getter
@Setter
public class ApiResponse<T>  {
    private int status;
    private String message;
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private T data;
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String error;
    private Metadata metadata;


    public ApiResponse(int status, String error, String message, T data, Metadata metadata) {
        this.status = status;
        this.error = error;
        this.message = message;
        this.data = data;
        this.metadata = metadata;
    }

    public static <T> ApiResponse<T> success(T data, Metadata metadata) {
        return new ApiResponse<>(200, null, "Success", data, metadata);
    }

    public static <T> ApiResponse<T> error(int status, String error, String message, Metadata metadata) {
        return new ApiResponse<>(status, error, message, null, metadata);
    }

}
